<include file="./Template/Admin/header.html" title="添加产品" />
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加新闻</h5>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <a href="{:U('Admin/Article/index')}" class="btn btn-outline btn-primary">返回新闻列表</a>
                        </div>
                    </div>
                    <form class="form-horizontal m-t" id="Forma" enctype="multipart/form-data" action="{:U('Admin/Article/Save')}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题:</label>
                            <div class="col-sm-8">
                                <input id="title" name="title" class="form-control" type="text" value="{$articleInfo.title}" aria-required="true" aria-invalid="false" class="valid">
                                <input id="id" name="id" value="{$articleInfo.id}" class="form-control" type="hidden">
                                <span class="help-block m-b-none"></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">图片:</label>
                            <div class="col-sm-8">
                                <input id="images" name="images" class="form-control" type="file" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">栏目:</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" name="cate_id">
                                    <option>-----请为新闻选择所属栏目-----</option>
                                    <volist name="category" id="v">
                                        <option value="{$v.id}" <if condition="$articleInfo['cate_id'] eq $v['id']"> selected</if>>{$v.title}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">关键词:</label>
                            <div class="col-sm-8">
                                <input id="tag" name="tag" value="{$articleInfo.tag}" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">作者:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$articleInfo.author}" name="author" id="author" />
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">内容:</label>
                            <div class="col-sm-8">
                                <!-- 加载编辑器的容器 -->
                                <script id="content" name="content" type="text/plain">{$articleInfo.content}</script>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">SEO标题:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$articleInfo.seo_title}" name="seo_title" id="seo_title" aria-required="true" aria-invalid="false" class="valid"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">SEO关键词:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$articleInfo.seo_keyword}" name="seo_keyword" id="seo_keyword" aria-required="true" aria-invalid="false" class="valid"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">SEO描述:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$articleInfo.seo_description}" name="seo_description" id="seo_description" aria-required="true" aria-invalid="false" class="valid"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">静态页:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$articleInfo.is_html}" name="is_html" id="is_html" />
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">排序:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$articleInfo.px}" name="px" id="px" />
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>



<script src="__ADMIN__js/jquery.min.js"></script>
<script src="__ADMIN__js/bootstrap.min.js"></script>
<script src="__ADMIN__js/plugins/layer.3/layer.js"></script>
<script src="__ADMIN__js/common.js"></script>
<script src="__ADMIN__js/content.min.js"></script>
<script src="__ADMIN__js/plugins/validate/jquery.validate.min.js"></script>
<script src="__ADMIN__js/plugins/validate/messages_zh.min.js"></script>
<script src="__ADMIN__js/plugins/switchery/switchery.js"></script>

<script type="text/javascript" src="__ADMIN__plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__ADMIN__plugins/ueditor/ueditor.all.js"></script>

<script>
    var elem = document.querySelector('.js-switch');
    var init = new Switchery(elem);

    var ue = UE.getEditor('content');

    $(function(){
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            }, success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
        }), $().ready(function () {
            var e = "<i class='fa fa-times-circle'></i> ";

            $("#Forma").validate({
                rules: {
                    title: "required",
                    tag: "required",
                    author: "required",
                    content: "required",
                    cate_id: "required",
                    seo_title: "required",
                    seo_keyword: "required",
                    seo_description: "required",
                    px: "required",
                    ix_html: "required"
                },
                messages: {
                    title: e + "请输入新闻标题",
                    tag: e + "请输入文章关键词",
                    author: e + "请输入文章作者",
                    content: e + "请输入文章内容",
                    cate_id: e + "请为文章选择所属栏目",
                    seo_title: e + "请输入文章的SEO标题",
                    seo_keyword: e + "请输入文章的SEO关键词",
                    seo_description: e + "请输入文章的SEO描述",
                    px: e + "请输入文章的排序",
                    ix_html: e + "文章页面是否静态化"
                },
                submitHandler: function(form){
                    var data = new  FormData(document.getElementById('Forma'));
                    $.ajax({
                        url:$(form).attr('action'),
                        type:"POST",
                        data:data,
                        cache: false,
                        processData:false,
                        contentType:false,
                        success:function(data){
                            if(data.status > 0){
                                common.error(data.msg);
                            }else{
                                common.success(data.msg,"{:U('Admin/Article/index')}");
                            }
                        },
                        dataType:'JSON'
                    });
                    return false;
                }
            });
        });

    });
</script>
</body>
</html>
